$(function(){
    $(".btn-active").click(function (event) {
        event.preventDefault()
        $this = $(this)
        var is_active = parseInt($this.attr("data-active"))
        var message = is_active?"您确定要下架该图书吗?":"您确定要上架该图书吗?"
        var result =confirm(message)
        var book_id = parseInt($this.attr("data-book-id"))
        if(!result){
            return
        }
        var data = {
            is_active:is_active?0:1
        }
        $.ajax({
            url:"/cms/book/active/"+book_id,
            data:data,
            success:function () {
                window.location.reload()
            },
            fail:function (error) {
                alert(error.message)
            }
        })
    })
    $(".btn-return_book").click(function (event) {
        event.preventDefault()
        $this =$(this)
        var book_id= parseInt($this.attr("data-book-id"))
        var user_id= parseInt($this.attr("data-user-id"))
        $.ajax({
            url:"/cms/update/borrow_status",
            data:{user_id,book_id},
            method:"POST",
            success:function (res) {
                alert("还书成功")
                window.location.reload()
            },
            fail:function (err){
                alert("还书失败"+err.message)
            }
        })
    })
})